/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.j002.requirementengineeringmuni.entities;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;

/**
 *
 * @author stefan
 */
public class Card {
    
    public static final String RESOURCES_PATH = "src" + File.separator + "main" + File.separator + "resources" + File.separator;
    
    private final Sign sign;
    private final Value value;
    private BufferedImage image;
    
    public Card(Sign sign, Value value) {
        this.sign = sign;
        this.value = value;
        try {                
            String imageName = RESOURCES_PATH + sign.getValue() + value.getValue() + ".jpg";
            File imageFile = new File(imageName);
            this.image = ImageIO.read(imageFile);
        } catch (IOException ex) {
            this.image = new BufferedImage(80, 117, BufferedImage.TYPE_INT_RGB);
        }
    }

    public Sign getSign() {
        return sign;
    }

    public Value getValue() {
        return value;
    }

    public BufferedImage getImage() {
        return image;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 11 * hash + (this.sign != null ? this.sign.hashCode() : 0);
        hash = 11 * hash + (this.value != null ? this.value.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Card other = (Card) obj;
        if (this.sign != other.sign) {
            return false;
        }
        if (this.value != other.value) {
            return false;
        }
        return true;
    }
    
    public static enum Sign {
        SPADES("spades", "\u2660"), HEARTS("hearts", "\u2665"), DIAMONDS("diamonds", "\u2666"), CLUBS("clubs", "\u2663");
        private String value;
        private String code;
        Sign(String value, String code) {
            this.value = value;
            this.code = code;
        }
        public String getValue() { return this.value; }
        public String getCode() { return this.code; }
    }
    
    public static enum Value {
        TWO("2"), THREE("3"), FOUR("4"), FIVE("5"), 
        SIX("6"), SEVEN("7"), EIGHT("8"), NINE("9"), 
        TEN("10"), JACK("J"), QUEEN("Q"), KING("K"), ASE("A");
        private String value;
        Value(String value) {
            this.value = value;
        }
        public String getValue() { return this.value; }
    }
}
